import db from '../config/sqlcfg';
import EthTokenHandle from '../server/coin/ethToken/EthTokenHandle';
import {isUndefined} from "util";
import task from 'node-schedule';
import {logger} from '../models/LogModel';

var index = 1;
logger('task').info('任务开启');

task.scheduleJob('* 30 * * * *', () => {
  logger('task').info('执行'+ index + '次');
  db.query('select transaction_hash from eth_transaction').then(async res => {
    for(const i of res) {
      const ethToken = new EthTokenHandle(i.transaction_hash);
      const tokenTransaction = await ethToken.buildTransactionMessage();
      if(!isUndefined(tokenTransaction)) {
        await ethToken.affertBlock();
        await ethToken.transfer().catch(error => {
          console.log(error);
        });
      }
    }
    logger('task').info('success');
    index++;
  });
});
